/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sdd.facades.persistence;

import com.sdd.entities.FeatureCategory;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

/**
 *
 * @author T
 */
@Stateless
public class FeatureCategoryPersistenceFacade extends AbstractPersistenceFacade<FeatureCategory> {

    @PersistenceContext(unitName = "SDDStore-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public FeatureCategoryPersistenceFacade() {
        super(FeatureCategory.class);
    }

    public FeatureCategory findByName(String name) {

        CriteriaQuery<FeatureCategory> cq = em.getCriteriaBuilder().createQuery(FeatureCategory.class);
        Root<FeatureCategory> fc = cq.from(FeatureCategory.class);
        cq.where(em.getCriteriaBuilder().equal(fc.get("name"), name));
        List<FeatureCategory> resultList = em.createQuery(cq).getResultList();
        if (resultList != null && resultList.size() > 0) {
            return resultList.get(0);
        } else {
            return null;
        }
    }
}
